package com.up2566.demo.model;

import com.up2566.demo.enums.DataEnum;
import com.up2566.demo.model.dto.ComputeDto;
import java.math.BigDecimal;

/**
 * 计算器动态数据比率
 *
 * @author up
 * @date 2021/1/11
 */
public class ComputeDataModel {

    BigDecimal blByQd;

    BigDecimal blByZj;

    BigDecimal blByMz;

    BigDecimal blByHx;

    BigDecimal blBySp;

    BigDecimal zuiZhongPro;

    BigDecimal zuiZhong;

    public static ComputeDataModel getComputeData(ComputeDto dto) {
        ComputeDataModel model = new ComputeDataModel();
        model.blByQd = computeBlByQd(dto.getQiangdu(), dto.getQiangdu1(), dto.getQiangdu2());
        model.blByZj = computeBlByZj(dto.getZhuanjing());
        model.blByMz = computeBlByMz(dto.getZhuanzhu());
        model.blByHx = computeBlByHx(dto.getHuixin(), model.blByMz);
        model.blBySp = BigDecimal.ONE.subtract(model.blByMz);
        model.zuiZhongPro = computeZuiZhongPro(dto.getGongjili(), dto.getGongjili1(), model.blByQd);
        model.zuiZhong = computeZuiZhong(dto.getGongjili(), model.blByQd);
        return model;
    }

    /**
     * 获取最终攻击力
     * 0.99 为模拟攻击力上下波动, 0.99为实际面板最终攻击力的收益
     */
    private static BigDecimal computeZuiZhong(String gongjili, BigDecimal qdbl) {
        return new BigDecimal(gongjili).multiply(new BigDecimal("0.99")).multiply(qdbl);
    }

    /**
     * 获取前一分钟最终攻击力
     */
    private static BigDecimal computeZuiZhongPro(String gongjili, String gongjili1, BigDecimal qdbl) {
        return (new BigDecimal(gongjili).add(new BigDecimal("".equals(gongjili1) ? "0" : gongjili1))).multiply(new BigDecimal("0.99"))
            .multiply(qdbl);
    }

    /**
     * 获取强度比率
     */
    private static BigDecimal computeBlByQd(String qiangdu, String qiangdu1, String qiangdu2) {
        BigDecimal ewQd = BigDecimal.ZERO;
        if ("on".equals(qiangdu1)) {
            ewQd = ewQd.add(new BigDecimal("0.01"));
        }
        if ("on".equals(qiangdu2)) {
            ewQd = ewQd.add(new BigDecimal("0.01"));
        }
        return new BigDecimal(qiangdu).multiply(DataEnum.BL.value()).add(BigDecimal.ONE).add(ewQd);
    }

    /**
     * 获取专精比率
     */
    private static BigDecimal computeBlByZj(String zhuanjing) {
        return new BigDecimal(zhuanjing).multiply(DataEnum.BL.value());
    }

    /**
     * 获取命中比率
     */
    private static BigDecimal computeBlByMz(String zhuanzhu) {
        return new BigDecimal(zhuanzhu).divide(new BigDecimal("100")).setScale(4, BigDecimal.ROUND_HALF_UP);
    }

    /**
     * 计算专精比率
     */
    private static BigDecimal computeBlByHx(String huixin, BigDecimal mz) {
        return new BigDecimal(huixin).divide(new BigDecimal("100")).multiply(mz);
    }

    public BigDecimal getBlByQd() {
        return blByQd;
    }

    public BigDecimal getBlByZj() {
        return blByZj;
    }

    public BigDecimal getBlByMz() {
        return blByMz;
    }

    public BigDecimal getBlByHx() {
        return blByHx;
    }

    public BigDecimal getBlBySp() {
        return blBySp;
    }

    public BigDecimal getZuiZhongPro() {
        return zuiZhongPro;
    }

    public BigDecimal getZuiZhong() {
        return zuiZhong;
    }
}
